package cn.gson.crm.controller.dept;

import java.util.List;
import java.util.Map;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.gson.crm.controller.BaseServlet;
import cn.gson.crm.model.dao.DeptDao;
import cn.gson.crm.model.entity.Dept;

@WebServlet("/dept/son")
public class DeptSonServlet extends BaseServlet{

	/**
	 * 子部门查询
	 */
	private static final long serialVersionUID = 1L;
	private DeptDao deptDao = new DeptDao();

		@Override
		protected void get(HttpServletRequest request, HttpServletResponse response) throws Exception {
			String id = request.getParameter("id");
			//父部门
			Dept parentDept = deptDao.getDeptById(1, id);
			String deptName = request.getParameter("deptName");
			String deptManager = request.getParameter("deptManager");
			String p = request.getParameter("page");
			if (p == null || p.isEmpty()) {
				p = "1";
			}
			Integer page = Integer.parseInt(p);
			List<Dept> deptList = deptDao.getSonDept(page, deptName, deptManager, 1, id);

			
			Integer totalPage = deptDao.getSonDeptTotalPage(1, id, deptName, deptManager);
			request.setAttribute("parentDept", parentDept);
			request.setAttribute("page", page);
			request.setAttribute("queryString", noPageQueryString(request));
			request.setAttribute("totalPage", totalPage);
			request.setAttribute("deptList", deptList);
			setReqAndRemoveRes("cantBeDeleDeptList",request,"cantBeDeleDeptList");
			setReqAndRemoveRes("deleErro",request,"deleErro");
			getServletPathAndForward1(request, "/dept/son_dept.jsp");
			//forward("/dept/son_dept.jsp");
		}
		
}
